package com.webside.points.controller;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.webside.points.model.AnswerEntity;
import com.webside.points.model.ExpertEntity;
import com.webside.points.model.IssueEntity;
import com.webside.points.model.IssueTypeEntity;
import com.webside.points.model.LikeEntity;
import com.webside.points.model.PostEntity;
import com.webside.points.model.PostTypeEntity;
import com.webside.points.model.UserEntity;
import com.webside.points.service.AnswerService;
import com.webside.points.service.ExpertService;
import com.webside.points.service.IssueService;
import com.webside.points.service.IssueTypeService;
import com.webside.points.service.LikeService;
import com.webside.points.service.PostService;
import com.webside.points.service.PostTypeService;
import com.webside.points.service.UserService;
import com.webside.points.wechat.Aes;
import com.webside.points.wechat.Constant;
import com.webside.points.wechat.HttpUtil;
import com.webside.points.wechat.RandomGenerator;
import com.webside.points.wechat.Signature;
import com.webside.points.wechat.Util;
import com.webside.points.wechat.WeChatConfig;
import com.webside.points.wechat.Wechat;
import com.webside.points.wechat.XMLParser;


@Controller
@Scope("prototype")
@RequestMapping("/api/")
public class ApiContronller {
	
	@Autowired
	UserService userService;
	
	@Autowired
	IssueTypeService issueTypeService;
	
	@Autowired
	IssueService issueService;
	
	@Autowired
	AnswerService answerService;
	
	@Autowired
	ExpertService expertService;
	
	@Autowired
	PostService postService;
	
	@Autowired
	LikeService likeService;
	
	@Autowired
	PostTypeService postTypeService;
	
	/*
	 * 根据openId查询用户信息
	 */
	@RequestMapping("findByOpenId")
	public void findByOpenId(String openId,HttpServletResponse response){
		
		UserEntity userEntity = userService.findByOpenId(openId);
		String json = JSON.toJSONString(userEntity);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
	}
	
	/*
	 * 增加用户信息
	 */
	@RequestMapping("insertUser")
	public void insertUser(UserEntity userEntity,HttpServletResponse response){
		
		try {
			userEntity.setWechatId(URLDecoder.decode(userEntity.getWechatId(),"UTF-8"));
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		}
		userEntity.setStatus("1");
		userEntity.setManageStatus("2");
		userEntity.setStudyNumber(0);
		userEntity.setCreateTime(new Date(System.currentTimeMillis()));
		userEntity.setPayment(0.00);
		
		System.out.println("userEntity:>>>"+userEntity);
		int result = userService.insert(userEntity);
		String json = JSON.toJSONString(result);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
	}
	/*
	 * 查询所有问题类型
	 */
	@RequestMapping("findIssueTypeAll")
	public void findIssueTypeAll(HttpServletResponse response){
		
		List<IssueTypeEntity> list = issueTypeService.findAll();
		String json = JSON.toJSONString(list);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
	}
	/*
	 * 增加问题
	 */
	@RequestMapping("insertIssue")
	public void insertIssue(IssueEntity issueEntity,HttpServletResponse response,HttpServletRequest request){

		try {
			issueEntity.setIssueContent(URLDecoder.decode(issueEntity.getIssueContent(),"UTF-8"));
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		}

		
		System.out.println("issueEntity:>>>"+issueEntity);
		issueEntity.setStatus("1");
		issueEntity.setCreateTime(new Date(System.currentTimeMillis()));
		int result = issueService.insert(issueEntity);
		String json = JSON.toJSONString(result);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
	}
	/*
	 * 查询问题记录
	 */
	@RequestMapping("findIssueRecord")
	public void findIssueRecord(int page,int size,int userId,HttpServletResponse response){
		
		Map<String,Integer> map=new HashMap<String,Integer>();
		map.put("userId", userId);
		
		 int cPage=page;
		 cPage=(cPage-1)*10;
		 map.put("page", cPage);
		 map.put("size", size);
		 
		List<IssueEntity> issueList=issueService.findRecord(map);
		for(int i=0;i<issueList.size();i++){
			int like=0;
			int dislike=0;
			IssueEntity issueEntity = issueList.get(i);
			Map<String, Integer> mapAnswer = new HashMap<String, Integer>();
			mapAnswer.put("issueId", issueEntity.getId());
			List<AnswerEntity> answerList = answerService.findByIssueId(mapAnswer);
			System.out.println("answerList：>>>"+answerList);
			if(answerList.size()!=0){
				for(int j=0;j<answerList.size();j++){
					AnswerEntity answerEntity = answerList.get(j);
					like=like+answerEntity.getLikeMark();
					dislike=dislike+answerEntity.getDislikeMark();
				}
				issueEntity.setLike(like);
				issueEntity.setDislike(dislike);
			}
			
			String array[] = issueEntity.getCreateDateFormat().split(" ");
			String date[] = array[0].split("-");
			String year = date[0];
			String month = Util.monthToEnglish(date[1]);
			String day = date[2];
			StringBuilder builder=new StringBuilder();
			builder.append(month+" ");
			builder.append(day+", ");
			builder.append(year+" ");
			builder.append(array[1]);
			issueEntity.setCreateDateFormat(builder.toString());
			
			
			issueList.set(i,issueEntity);
			
		}
		
		
		System.out.println("问题记录查询：>>>"+issueList);
		String json = JSON.toJSONString(issueList);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
	}
	/*
	 * 根据问题id查询信息
	 */
	@RequestMapping("findByIssueId")
	public void findByIssueId(int issueId,HttpServletResponse response){
		
		Map<String,Integer> map=new HashMap<String,Integer>();
		map.put("issueId", issueId);
		List<IssueEntity> issueList=issueService.findRecord(map);
		IssueEntity issueEntity =issueList.get(0);
		
		String array[] = issueEntity.getCreateDateFormat().split(" ");
		String date[] = array[0].split("-");
		String year = date[0];
		String month = Util.monthToEnglish(date[1]);
		String day = date[2];
		StringBuilder builder=new StringBuilder();
		builder.append(month+" ");
		builder.append(day+", ");
		builder.append(year+" ");
		builder.append(array[1]);
		issueEntity.setCreateDateFormat(builder.toString());
		
		String json = JSON.toJSONString(issueEntity);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
	}
	
	@RequestMapping("getSessionKey")
	public void getSessionKey(String code,HttpServletResponse response){
		StringBuilder buffer=new StringBuilder();
		buffer.append(WeChatConfig.SESSION_KEY_URL);
		buffer.append("?appid="+WeChatConfig.MINI_APP_ID);
		buffer.append("&secret="+WeChatConfig.MINI_APP_SECRET);
		buffer.append("&js_code="+code);
		buffer.append("&grant_type=authorization_code");
		String jsonResult = HttpUtil.sendGet(buffer.toString());
		
		String json = JSON.toJSONString(jsonResult);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
	}
	/*
	 * 获取用户信息
	 */
	@RequestMapping("getUserInfo")
	public void getUserInfo(String encryptedData, String iv, String sessionKey,HttpServletResponse response) throws Exception{
		String userInfo = Aes.decrypt(encryptedData, sessionKey, iv, "UTF-8");
		
		String json = JSON.toJSONString(userInfo);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
	}
	/*
	 * 统一支付
	 */
	@RequestMapping("getUnifiedOrder")
	@ResponseBody
	public String getUnifiedOrder(String openId,String amount,HttpServletRequest request){
		
		System.out.println("进入统一支付");
		String out_trade_no = UUID.randomUUID().toString().replaceAll("-", "");
		Map<String, String> paraMap = new HashMap<String, String>();
		paraMap.put("appid", WeChatConfig.MINI_APP_ID);
		paraMap.put("attach", "wechat");
		paraMap.put("body", "打赏");
		paraMap.put("mch_id", WeChatConfig.MCH_ID);
		paraMap.put("nonce_str", RandomGenerator.getRandomStringByLength(16));
		paraMap.put("openid", openId);
		paraMap.put("out_trade_no", out_trade_no);
		paraMap.put("spbill_create_ip", Wechat.getAddrIp(request));
		paraMap.put("total_fee", Util.amountTurnCent(amount));
		paraMap.put("trade_type", "JSAPI");
		paraMap.put("notify_url", Constant.REALM_URL +"service/reward-notify.jsp");
		String sign = Signature.getMD5Sign(paraMap);
		
		
		paraMap.put("sign", sign);
		
		
		//xml方式Post
		String xml = Wechat.ArrayToXml(paraMap);
		System.out.println("参数："+xml);
		/*try {
			xml=new String(xml.getBytes("ISO8859-1") ,"UTF-8");
			System.out.println(xml);
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		}*/
		String xmlStr = HttpUtil.sendPost(WeChatConfig.UNIFIED_ORDER_URL, xml,false,10);
		System.out.println("返回结果："+xmlStr);
		//预付商品id
		String prepay_id = "";
		if (xmlStr.indexOf("SUCCESS") != -1) {
			try {
				Map<String, String> map = XMLParser.getMapFromXML(xmlStr);
				prepay_id = (String) map.get("prepay_id");
			} catch (Exception e) {
			}
		}
		
		System.out.println("prepay_id："+prepay_id);
		//返回数据构造
		Map<String, String> payMap = new HashMap<String, String>();
		payMap.put("appId", WeChatConfig.MINI_APP_ID);
		payMap.put("timeStamp", Wechat.create_timestamp());
		payMap.put("nonceStr", RandomGenerator.getRandomStringByLength(16));
		payMap.put("package", "prepay_id=" + prepay_id);
		payMap.put("signType", "MD5");
		payMap.put("paySign", Signature.getMD5Sign(payMap));
		
		//返回JSON数据
		ObjectMapper objectMapper = new ObjectMapper();
		try {
			return  objectMapper.writeValueAsString(payMap);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	@RequestMapping("findByUnionId")
	public void findByUnionId(String unionId,HttpServletResponse response){
		
		UserEntity userEntity = userService.findByUnionId(unionId);
		String json = JSON.toJSONString(userEntity);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
	}
	/*
	 * 根据专家id查询信息
	 */
	@RequestMapping("findByExpertId")
	public void findByExpertId(int expertId,HttpServletResponse response){
		
		UserEntity userEntity = userService.findExpertId(expertId);
		String json = JSON.toJSONString(userEntity);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
	}
	/*
	 * 查询文章类型
	 */
	@RequestMapping("findPostType")
	public void findPostType(String name,HttpServletResponse response){
		
		if(name!=null){
			try {
				name=URLDecoder.decode(name,"utf-8");
				name="%"+name+"%";
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		
		List<PostTypeEntity> list = postTypeService.findPostType(name);
		
		System.out.println("文章类型list：>>>"+list);
		
		String json = JSON.toJSONString(list);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
	}
	/*
	 * 根据文章id查询信息
	 */
	@RequestMapping("findByPostTypeId")
	public void findByPostTypeId(int typeId,HttpServletResponse response){
		PostTypeEntity postTypeEntity = postTypeService.findById(typeId);
		
		if(postTypeEntity!=null){
			postTypeEntity.setBrowseNumber(postTypeEntity.getBrowseNumber()+1);
			
			System.out.println(postTypeEntity);
			postTypeService.updateBrowseNumber(postTypeEntity);
		}
		
		List<PostEntity> list = postService.findByPostTypeId(typeId);
		
		String json = JSON.toJSONString(list);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
		
	}
	/*
	 * 根据文章ID查询文章内容
	 */
	@RequestMapping("findByPostId")
	public void findByPostId(int id,HttpServletResponse response){
		PostEntity postEntity=postService.findById(id);
		String json = JSON.toJSONString(postEntity);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
	}
	
	/*
	 * 查询所有专家
	 */
	@RequestMapping("findAllExpert")
	public void findAllExpert(int page,int size,HttpServletResponse response){
		Map<String, Integer> map = new HashMap<String, Integer>();
		
		int cPage=page;
		 cPage=(cPage-1)*10;
		 map.put("page", cPage);
		 map.put("size", size);
		 
		List<ExpertEntity> list = expertService.finaAllExpert(map);
		
		for(int i=0;i<list.size();i++){
			ExpertEntity expertEntity =list.get(i);
			
			Map<String,Integer> expert=new HashMap<String,Integer>();
			expert.put("expertId", expertEntity.getId());
			List<IssueEntity> expertList=issueService.findRecord(expert);
			expertEntity.setAnswerCount(expertList.size());
			list.set(i,expertEntity);
		}
		
		
		System.out.println("list:>>>"+list);
		
		String json = JSON.toJSONString(list);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
	}
	
	@RequestMapping("findByAnswerId")
	public void findByAnswerId(int page,int size,int issueId,int userId,HttpServletResponse response){
		Map<String, Integer> map = new HashMap<String, Integer>();
		map.put("issueId", issueId);
		
		int cPage=page;
		 cPage=(cPage-1)*10;
		 map.put("page", cPage);
		 map.put("size", size);
		
		List<AnswerEntity> answerList = answerService.findByIssueId(map);
		
		for(int i=0;i<answerList.size();i++){
			AnswerEntity answerEntity = answerList.get(i);
			answerEntity.setIsLike("false");
			answerEntity.setIsDisLike("false");
			System.out.println("answerEntity:>>>"+answerEntity);
			LikeEntity entity = new LikeEntity();
			entity.setAnswerId(answerEntity.getId());
			entity.setUserId(userId);
			System.out.println("entity:>>>"+entity);
			
			LikeEntity likeEntity = likeService.findById(entity);
			System.out.println("likeEntity：>>>"+likeEntity);
			
			if(likeEntity!=null){
				if(likeEntity.getLike().equals("am-icon-thumbs-up")){
					answerEntity.setIsLike("true");
				}else if(likeEntity.getDisLike().equals("am-icon-thumbs-down")){
					answerEntity.setIsDisLike("true");
				}
			}
			
			
			String array[] = answerEntity.getCreateDateFormat().split(" ");
			String date[] = array[0].split("-");
			String year = date[0];
			String month = Util.monthToEnglish(date[1]);
			String day = date[2];
			StringBuilder builder=new StringBuilder();
			builder.append(month+" ");
			builder.append(day+", ");
			builder.append(year+" ");
			builder.append(array[1]);
			answerEntity.setCreateDateFormat(builder.toString());
			
			answerList.set(i,answerEntity);
			System.out.println("answerEntity:<<<"+answerEntity);
		}
		
		
		String json = JSON.toJSONString(answerList);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
			
		}
	}
	
	@RequestMapping("findById")
	public void findById(int answerId,HttpServletResponse response){
		
		System.out.println("进入查询回答：>>>"+answerId);
		
		AnswerEntity answerEntity = answerService.findById(answerId);
		
		String json = JSON.toJSONString(answerEntity);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
			
		}
	}
	@RequestMapping("findLkie")
	public void findLkie(int answerId,int userId,HttpServletResponse response){
		
		LikeEntity entity = new LikeEntity();
		entity.setAnswerId(answerId);
		entity.setUserId(userId);
		
		LikeEntity likeEntity = likeService.findById(entity);
		
		String json = JSON.toJSONString(likeEntity);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
	}
	@RequestMapping("updatePraise")
	@ResponseBody
	public void updatePraise(int expertId,int answerId,String type,int userId){
		ExpertEntity expertEntity = expertService.findById(expertId);
		AnswerEntity answerEntity = answerService.findById(answerId);
		
		
		ExpertEntity expert=new ExpertEntity();
		expert.setId(expertEntity.getId());
		
		AnswerEntity answer = new AnswerEntity();
		answer.setId(answerId);
		
		LikeEntity likeEntity=new LikeEntity();
		likeEntity.setAnswerId(answerId);
		likeEntity.setUserId(userId);
		likeEntity.setCreateTime(new Date(System.currentTimeMillis()));
		likeEntity.setStatus("1");
		if(type.equals("like")){
			expert.setLikeCount(expertEntity.getLikeCount()+1);
			expert.setDislikeCount(expertEntity.getDislikeCount());
			answer.setLikeMark(answerEntity.getLikeMark()+1);
			answer.setDislikeMark(answerEntity.getDislikeMark());
			likeEntity.setLike("am-icon-thumbs-up");
			likeEntity.setDisLike("am-icon-thumbs-o-down");
			System.out.println(likeService.insert(likeEntity));
		}else{
			expert.setDislikeCount(expertEntity.getDislikeCount()+1);
			expert.setLikeCount(expertEntity.getLikeCount());
			answer.setDislikeMark(answerEntity.getDislikeMark()+1);
			answer.setLikeMark(answerEntity.getLikeMark());
			likeEntity.setDisLike("am-icon-thumbs-down");
			likeEntity.setLike("am-icon-thumbs-o-up");
			System.out.println(likeService.insert(likeEntity));
		}
		
		System.out.println("entity:>>>"+expert);
		
		expertService.updatePraise(expert);
		answerService.updateLikeMark(answer);
	}
	
	@RequestMapping("removePraise")
	@ResponseBody
	public void removePraise(int expertId,int answerId,String type,int userId){
		ExpertEntity expertEntity = expertService.findById(expertId);
		AnswerEntity answerEntity = answerService.findById(answerId);
		
		
		ExpertEntity expert=new ExpertEntity();
		expert.setId(expertEntity.getId());
		
		AnswerEntity answer = new AnswerEntity();
		answer.setId(answerId);
		
		LikeEntity likeEntity=new LikeEntity();
		likeEntity.setAnswerId(answerId);
		likeEntity.setUserId(userId);
		
		if(type.equals("like")){
			expert.setLikeCount(expertEntity.getLikeCount()-1);
			expert.setDislikeCount(expertEntity.getDislikeCount());
			answer.setLikeMark(answerEntity.getLikeMark()-1);
			answer.setDislikeMark(answerEntity.getDislikeMark());
			
			likeService.delete(likeEntity);
		}else{
			expert.setDislikeCount(expertEntity.getDislikeCount()-1);
			expert.setLikeCount(expertEntity.getLikeCount());
			answer.setDislikeMark(answerEntity.getDislikeMark()-1);
			answer.setLikeMark(answerEntity.getLikeMark());
			
			likeService.delete(likeEntity);
		}
		
		System.out.println("entity:>>>"+expert);
		
		expertService.updatePraise(expert);
		answerService.updateLikeMark(answer);
	}
	
	@RequestMapping("findExpertInfo")
	public void findExpertInfo(int page,int size,int expertId,HttpServletResponse response){
		
		Map<String, Object> map = new HashMap<String, Object>();
		
		
		if(expertId!=0){
			ExpertEntity expertEntity = expertService.findById(expertId);
			map.put("expertEntity", expertEntity);
			
			Map<String,Integer> expert=new HashMap<String,Integer>();
			expert.put("expertId", expertEntity.getId());
			List<IssueEntity> expertList=issueService.findRecord(expert);
			map.put("answerCount", expertList.size());
			
			Map<String,Integer> expertMap=new HashMap<String,Integer>();
			expertMap.put("expertId", expertEntity.getId());
			
			 int cPage=page;
			 cPage=(cPage-1)*10;
			 expertMap.put("page", cPage);
			 expertMap.put("size", size);
			 
			List<IssueEntity> issueList=issueService.findRecord(expertMap);
			
			for(int i=0;i<issueList.size();i++){
				IssueEntity issueEntity = issueList.get(i);
				
				
				int like=0;
				int dislike=0;
				Map<String, Integer> mapAnswer = new HashMap<String, Integer>();
				mapAnswer.put("issueId", issueEntity.getId());
				List<AnswerEntity> answerList = answerService.findByIssueId(mapAnswer);
				System.out.println("answerList：>>>"+answerList);
				if(answerList.size()!=0){
					for(int j=0;j<answerList.size();j++){
						AnswerEntity answerEntity = answerList.get(j);
						like=like+answerEntity.getLikeMark();
						dislike=dislike+answerEntity.getDislikeMark();
					}
					issueEntity.setLike(like);
					issueEntity.setDislike(dislike);
				}
				
				
				String array[] = issueEntity.getCreateDateFormat().split(" ");
				String date[] = array[0].split("-");
				String year = date[0];
				String month = Util.monthToEnglish(date[1]);
				String day = date[2];
				StringBuilder builder=new StringBuilder();
				builder.append(month+" ");
				builder.append(day+", ");
				builder.append(year+" ");
				builder.append(array[1]);
				issueEntity.setCreateDateFormat(builder.toString());
				
				issueList.set(i,issueEntity);
				System.out.println("issueEntity:>>>"+issueEntity);
			}
			
			map.put("issueList", issueList);
		}
		
		String json = JSON.toJSONString(map);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
	}
	@RequestMapping("findAnswerRecord")
	public void findAnswerRecord(int page,int size,int expertId,HttpServletResponse response){
		Map<String,Integer> expertMap=new HashMap<String,Integer>();
		expertMap.put("expertId", expertId);
		
		 int cPage=page;
		 cPage=(cPage-1)*10;
		 expertMap.put("page", cPage);
		 expertMap.put("size", size);
		 
		List<IssueEntity> issueList=issueService.findRecord(expertMap);
		
		for(int i=0;i<issueList.size();i++){
			IssueEntity issueEntity = issueList.get(i);
			
			String array[] = issueEntity.getCreateDateFormat().split(" ");
			String date[] = array[0].split("-");
			String year = date[0];
			String month = Util.monthToEnglish(date[1]);
			String day = date[2];
			StringBuilder builder=new StringBuilder();
			builder.append(month+" ");
			builder.append(day+", ");
			builder.append(year+" ");
			builder.append(array[1]);
			issueEntity.setCreateDateFormat(builder.toString());
			
			issueList.set(i,issueEntity);
			System.out.println("issueEntity:>>>"+issueEntity);
		}
		String json = JSON.toJSONString(issueList);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
	}
	
	
}
